package com.panshi.controller;

import com.google.common.collect.Maps;
import com.panshi.api.SysRoleApi;
import com.panshi.vo.R;
import com.panshi.vo.SysRoleVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hibernate.validator.constraints.pl.REGON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleApi sysRoleApi;

    @RequiresPermissions("role:list:*")
    @GetMapping("/pageRoleList")
    public Map<String,Object> pageRoleList(Integer page,Integer limit){
        R r = sysRoleApi.pageRoleList(page, limit);
        Map<String,Object> map = Maps.newHashMap();
        map.put("code",0);
        map.put("msg","success");
        map.put("count",r.getData().get("total"));
        map.put("data",r.getData().get("rows"));
        return map;
    }

    @RequiresPermissions("role:add:*")
    @PostMapping
    public R addRole(@RequestBody SysRoleVO sysRoleVO){
        return sysRoleApi.addSysRole(sysRoleVO);
    }

    @RequiresPermissions("role:edit:*")
    @PutMapping
    public R editRole(@RequestBody SysRoleVO sysRoleVO){
        return sysRoleApi.editSysRole(sysRoleVO);
    }


    @RequiresPermissions("role:del:*")
    @DeleteMapping("/{id}")
    public R delRole(@PathVariable("id")Integer id){
        return sysRoleApi.delSysRole(id);
    }


    @GetMapping("/xmSelectRoleList")
    public R xmSelectRoleList(){
        return sysRoleApi.selectRoleList();
    }

    @GetMapping("/getRoleSelectByUserId/{id}")
    public R xmSelectRoleListByUid(@PathVariable("id")Integer id){
        return sysRoleApi.getRoleSelectByUserId(id);
    }

}
